Imports System
Imports System.Collections.Generic
Imports BA.Chat

Partial Class Chat
    Inherits WebPageBase

    Private m_security As New Security
    Private m_chat As ChatMain = ChatMain.ActiveChats(0)
    Private m_chatuser As ChatUser = ChatUser.ActiveChatters(Membership.GetUser(m_security.CurrentUser).ProviderUserKey)

    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit

        Try
            If Not Profile.UI.Theme = String.Empty Then
                If IsThemeValid(Profile.UI.Theme.ToString) Then
                    Page.Theme = Profile.UI.Theme
                Else
                    Page.Theme = WebBase.AppTheme
                End If
            Else
                Page.Theme = WebBase.AppTheme
            End If
        Catch ex As Exception
            Page.Theme = WebBase.AppTheme
        End Try

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        _UpdateChatterList()
        _UpdateChatMessageList()
    End Sub

    Private Sub _UpdateChatMessageList()
        ChatMessageList.DataSource = m_chat.Messages
        ChatMessageList.DataBind()

        uxtest.DataSource = m_chat.Messages
        uxtest.DataBind()
    End Sub

    Private Sub _UpdateChatterList()
        ChattersBulletedList.DataSource = m_chat.Chatters
        ChattersBulletedList.DataTextField = "Name"
        ChattersBulletedList.DataBind()
    End Sub

    Protected Sub SendButton_Click(ByVal sender As Object, ByVal e As EventArgs)
        If Not String.IsNullOrEmpty(NewMessageTextBox.Text) Then
            Dim messageSent As String = m_chat.SendMessage(m_chatuser, NewMessageTextBox.Text)
            NewMessageTextBox.Text = String.Empty
        End If
        _UpdateChatterList()
        _UpdateChatMessageList()
    End Sub

End Class
